<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增员工')" />
	<th:block th:include="include :: select2-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-add" class="form-horizontal">
            <input name="roleId" id="roleId" th:value="${roleId}" class="form-control" type="hidden"/>
            <div class="row">
            	<div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">岗位功能：</label>
                        <div class="col-sm-8">
                            <div style="margin-bottom: 8px;">
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="1" style="margin-right: 5px;"/><span style="margin-right: 20px;">产品出库</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="16" style="margin-right: 5px;"/><span style="margin-right: 20px;">商城客户订单</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="5" style="margin-right: 5px;"/><span style="margin-right: 20px;">待配货订单</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="2" style="margin-right: 5px;"/><span style="margin-right: 20px;">领取配货单</span>
                                </div>
                            </div>
                           <div style="margin-bottom: 8px;">
                               <div style="float: left">
                                   <input type="checkbox" name="homeMenu" value="7" style="margin-right: 5px;"/><span style="margin-right: 20px;">配货中订单</span>
                               </div>
                               <div style="float: left">
                                   <input type="checkbox" name="homeMenu" value="6" style="margin-right: 5px;"/><span style="margin-right: 20px;">待验货订单</span>
                               </div>
                               <div style="float: left">
                                   <input type="checkbox" name="homeMenu" value="11" style="margin-right: 5px;"/><span style="margin-right: 20px;">出库单审核</span>
                               </div>
                               <div >
                                   <input type="checkbox" name="homeMenu" value="4" style="margin-right: 5px;"/><span style="margin-right: 20px;">待配送订单</span>
                               </div>
                           </div>
                        <div style="margin-bottom: 8px;">
                            <div style="float: left">
                                <input type="checkbox" name="homeMenu" value="8" style="margin-right: 5px;"/><span style="margin-right: 20px;">已配送订单</span>
                            </div>
                            <div style="float: left">
                                <input type="checkbox" name="homeMenu" value="12" style="margin-right: 5px;"/><span style="margin-right: 20px;">产品入库</span>
                            </div>
                            <div style="float: left">
                                <input type="checkbox" name="homeMenu" value="17" style="margin-right: 5px;"/><span style="margin-right: 20px;">入库单审核</span>
                            </div>
                            <div >
                                <input type="checkbox" name="homeMenu" value="10" style="margin-right: 5px;"/><span style="margin-right: 20px;">客户退货</span>
                            </div>
                        </div>
                            <div style="margin-bottom: 8px;">

                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="18" style="margin-right: 5px;"/><span style="margin-right: 20px;">客户退货单审核</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="14" style="margin-right: 5px;"/><span style="margin-right: 20px;">返回厂家</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="19" style="margin-right: 5px;"/><span style="margin-right: 20px;">退回厂家单审核</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="9" style="margin-right: 5px;"/><span style="margin-right: 20px;">客户信息</span>
                                </div>
                            </div>
                            <div style="margin-bottom: 8px;">

                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="13" style="margin-right: 5px;"/><span style="margin-right: 20px;">供应商信息</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="15" style="margin-right: 5px;"/><span style="margin-right: 20px;">产品位置调拨</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="20" style="margin-right: 5px;"/><span style="margin-right: 20px;">新增产品</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="21" style="margin-right: 5px;"/><span style="margin-right: 20px;">挂起订单</span>
                                </div>

                            </div>

                            <div style="margin-bottom: 8px;">

                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="22" style="margin-right: 5px;"/><span style="margin-right: 20px;">订单结算</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="23" style="margin-right: 5px;"/><span style="margin-right: 20px;">特价产品</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="24" style="margin-right: 5px;"/><span style="margin-right: 20px;">统计</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="25" style="margin-right: 5px;"/><span style="margin-right: 20px;">物流代收结算</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="26" style="margin-right: 5px;"/><span style="margin-right: 20px;">结算记录</span>
                                </div>
                            </div>

                            <div style="margin-bottom: 8px;">

                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="26" style="margin-right: 5px;"/><span style="margin-right: 20px;">结算记录</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="28" style="margin-right: 5px;"/><span style="margin-right: 20px;">待入库订单</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="27" style="margin-right: 5px;"/><span style="margin-right: 20px;">日常费用</span>
                                </div>
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="29" style="margin-right: 5px;"/><span style="margin-right: 20px;">调货清单</span>
                                </div>
                            </div>
                            <div style="margin-bottom: 8px;">
                                <div style="float: left">
                                    <input type="checkbox" name="homeMenu" value="30" style="margin-right: 5px;"/><span style="margin-right: 20px;">待入库调货单</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="31" style="margin-right: 5px;"/><span style="margin-right: 20px;">缺货提醒</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="33" style="margin-right: 5px;"/><span style="margin-right: 20px;">账务管理</span>
                                </div>
                                <div >
                                    <input type="checkbox" name="homeMenu" value="34" style="margin-right: 5px;"/><span style="margin-right: 20px;">利润管理</span>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">菜单权限：</label>
                        <div class="col-sm-8">
                            <label class="check-box">
                                <input type="checkbox" value="1">展开/折叠</label>
                            <label class="check-box">
                                <input type="checkbox" value="2">全选/全不选</label>
                            <label class="check-box">
                                <input type="checkbox" value="3" checked>父子联动</label>
                            <div id="menuTrees" class="ztree ztree-border"></div>
                        </div>
                    </div>
                </div>
            </div>
            <!--<h4 class="form-header h4">岗位功能</h4>
            <div class="row">
                    <form class="form-horizontal m" id="form-role-add">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">岗位详细功能：</label>
                            <div class="col-sm-8">
                                <label class="check-box">
                                    <input type="checkbox" value="1">展开/折叠</label>
                                <label class="check-box">
                                    <input type="checkbox" value="3" checked>父子联动</label>
                                <div id="menuTrees" class="ztree ztree-border"></div>
                            </div>
                        </div>
                    </form>
            </div>-->
        </form>
    </div>
      
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
    <th:block th:include="include :: ztree-js" />
	<script>
	    var prefix = ctx + "system/user";

        $(function() {
            //初始化菜单权限
            var url;
            if($("#roleId").val() == 999){
                 url= ctx + "system/menu/roleMenuTreeData?roleId=" + $("#roleId").val();
                //初始化APP功能权限
                $.ajax({
                    url: ctx + "system/role/getRole/999",
                    type: "POST",
                    contentType: false,
                    success: function(result) {
                        debugger;
                        if(result.msg == "success"){
                            var homeMenu = result.data.remark;
                            $(homeMenu.split(",")).each(function (i,e) {
                                $("input[name='homeMenu'][value='" + e + "']").prop("checked", true);})
                        }
                    }
                })
            }else{
                 url = ctx + "system/menu/roleMenuTreeData";
            }
            var options = {
                id: "menuTrees",
                url: url,
                check: { enable: true },
                expandLevel: 0
            };
            $.tree.init(options);
        });

        function submitHandler() {
            var spCodesTemp = "";
            $('input:checkbox[name=homeMenu]:checked').each(function(i){
                if(0==i){
                    spCodesTemp = $(this).val();
                }else{
                    spCodesTemp += (","+$(this).val());
                }
            });
            var menuIds = $.tree.getCheckedNodes();

            //临时保存数据
            var roleName = "临时数据";
            var roleKey = "linshi";
            var remark = spCodesTemp;
            var menuIds = $.tree.getCheckedNodes();
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "system/role/add",
                data : {
                    "roleId": 999,
                    "roleName": roleName,
                    "roleKey": roleKey,
                    "roleSort": 999,
                    "remark": remark,
                    "status": '0',
                    "menuIds": menuIds
                },
                async : false,
                error : function(request) {
                },
                success : function(data) {
                }
            });

            $.modal.close();
            // 父页面的变量
            parent.$('#homeMenu').val(spCodesTemp);
            parent.$('#functionMenu').val(menuIds);
            // 父页面的方法
            parent.addTableColumn();

	    }

		/*function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}*/
       function showRole() {
           //获取被选中的option标签
           var vs = $('#role  option:selected').val();
           if(vs != '' && vs != NaN && vs !=undefined){
               var url = ctx + "system/menu/roleMenuTreeData?roleId=" + vs;
               var options = {
                   id: "menuTrees",
                   url: url,
                   check: { enable: true },
                   expandLevel: 0
               };
               $.tree.init(options);
           }
        };

        $('input').on('ifChanged', function(obj){
            var type = $(this).val();
            var checked = obj.currentTarget.checked;
            if (type == 1) {
                if (checked) {
                    $._tree.expandAll(true);
                } else {
                    $._tree.expandAll(false);
                }
            } else if (type == "2") {
                if (checked) {
                    $._tree.checkAllNodes(true);
                } else {
                    $._tree.checkAllNodes(false);
                }
            } else if (type == "3") {
                if (checked) {
                    $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
                } else {
                    $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
                }
            }
        })

        function closeItem() {
            $.modal.close();
        }

    </script>
</body>
</html>